package com.song.stormdemo1;

import java.util.Map;

import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;

public class SplitBolt extends BaseRichBolt {
	
	
	private Map conf;
	private TopologyContext context;
	private OutputCollector collector;
	
	public void execute(Tuple tuple) {
		String line  = tuple.getStringByField("line");
		String[] words = line.split("\\s");
		for(String word: words)
		{
			System.err.println(word);
			collector.emit(new Values(word));
		}
	}

	public void prepare(Map map, TopologyContext context, OutputCollector collector) {
		this.conf = map;
		this.context = context;
		this.collector = collector;
	}

	public void declareOutputFields(OutputFieldsDeclarer declarer) {
		declarer.declare(new Fields("word"));
	}

}
